package com.qf.boot2203.aspect;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Aspect
@Component
@Slf4j
public class NullValidateAspect {

    @Pointcut("@annotation(com.qf.boot2203.annotation.NullValidate)")
    public void nullValidate(){}


    @Before("nullValidate()")
    public void before(JoinPoint joinPoint) throws Exception {
        Object[] args = joinPoint.getArgs();
        for (int i = 0; i < args.length ; i++) {
            if (null == args[i]){
                log.error("调用方法{}时，第{}个参数为空",joinPoint.getSignature(),i);
                throw new Exception("参数为空");
            }
        }
    }
}
